package com.naizhuai.ui.task.multtype;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.naizhuai.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.drakeet.multitype.ItemViewBinder;

/**
 * @author：lichenxi
 * @date 2018/5/9 17
 * email：525603977@qq.com
 * Fighting
 */
public class TaskInfoViewBinder extends ItemViewBinder<TaskInfo, TaskInfoViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_task_info, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull TaskInfo taskInfo) {
        Context context=holder.itemView.getContext();
        String completeCount = String.format(context.getText(R.string.mission_number_finished).toString(), taskInfo.completeTaskCount);
        String unCompleteCount = String.format(context.getText(R.string.mission_number_unfinished).toString(), taskInfo.unCompleteTaskCount);
        holder.completeTaskCount.setText(completeCount);
        holder.unCompleteTaskCount.setText(unCompleteCount);
        holder.keyresult.setText(taskInfo.keyresult);
        holder.finishtime.setText(taskInfo.finishTime);
        holder.taskExplain.setText(taskInfo.getTaskExplain());
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.keyresult)
        TextView keyresult;
        @BindView(R.id.finishtime)
        TextView finishtime;
        @BindView(R.id.task_explain)
        TextView taskExplain;
        @BindView(R.id.finished)
        TextView completeTaskCount;
        @BindView(R.id.unfinish)
        TextView unCompleteTaskCount;
        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
